﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media.Animation;
using System.Windows;
    
namespace TouchControls
{
    public static class AnimHelpers
    {
        public static DoubleAnimation DoubleAnim(this Storyboard stb, string targetName, string property, double? fromValue = null, double? toValue = null, double duration = 250, IEasingFunction easing = null)
        {
            DoubleAnimation anim = new DoubleAnimation();
            anim.Duration = new Duration(TimeSpan.FromMilliseconds(duration));
            if (easing != null)
                anim.EasingFunction = easing;

            if (fromValue.HasValue)
                anim.From = fromValue;

            if (toValue.HasValue)
                anim.To = toValue;

            Storyboard.SetTargetName(anim, targetName);
            Storyboard.SetTargetProperty(anim, new PropertyPath(property));
            if (stb != null)
                stb.Children.Add(anim);
            return anim;
        }

        public static DoubleAnimation DoubleAnim(this Storyboard stb, UIElement element, string property, double? fromValue = null, double? toValue = null, double duration = 250, IEasingFunction easing = null)
        {
            DoubleAnimation anim = new DoubleAnimation();
            anim.Duration = new Duration(TimeSpan.FromMilliseconds(duration));
            if (easing != null)
                anim.EasingFunction = easing;

            if (toValue.HasValue)
                anim.To = toValue;

            Storyboard.SetTarget(anim, element);
            Storyboard.SetTargetProperty(anim, new PropertyPath(property));
            if (stb != null)
                stb.Children.Add(anim);
            return anim;
        }
    }
}
